package sendmail;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Text;
public class SubmitContent extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String lang = req.getParameter(Constants.LANG);
		String subject = req.getParameter(Constants.SUBJECT);
		String body = req.getParameter(Constants.BODY);
		Text text = new Text(body);
		DatastoreService dataService = DatastoreServiceFactory
				.getDatastoreService();
		Entity entity = new Entity(Constants.KIND_MAIL_CONTENT, lang);
		entity.setProperty(Constants.SUBJECT, subject);
		entity.setProperty(Constants.BODY, text);
		dataService.put(entity);
		
		req.setAttribute(Constants.LANG, lang);
		req.setAttribute(Constants.SUBJECT, subject);
		req.setAttribute(Constants.BODY, body);

		req.getRequestDispatcher("/admin/mail_contents.jsp").forward(req, resp);
	}
}
